package com.yiwyn;


import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.AviatorEvaluatorInstance;
import com.googlecode.aviator.Expression;
import com.yiwyn.domain.User;

import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        User user = new User();
        user.setName("Yiwyn");
        user.setId(1);
        // 创建执行器
        AviatorEvaluatorInstance engine = AviatorEvaluator.getInstance();
        // 表达式

        String expression = "if (user.id > 2) {return user.id;} else {return user.name;}";

        Expression exp = engine.compile(expression, true);
        Map<String, Object> map = new HashMap<>();
        map.put("user", user);

        Object user1 = exp.execute(map);
        System.out.println(user1);
    }
}